﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DX_DailyUtil_1._0._1.ks.objt;
using DX_DailyUtil_1._0._1.ks.objt.hitch;
using DX_DailyUtil_1._0._1.ks.util;
using DX_DailyUtil_1._0._1.ks.ctrl.hitch;
using System.Windows.Threading;
using System.Threading;
using DX_DailyUtil_1._0._1.ks.ui.effect;

namespace DX_DailyUtil_1._0._1
{
    public partial class MainPage : UserControl
    {

        private Util_Html mUtilHtml = null;

        private Slide mSlide = null;

        private Deal_HitchRecord mDeal_HitchRecord;

        public MainPage()
        {
            InitializeComponent();
            mUtilHtml = new Util_Html();
        }

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            mDeal_HitchRecord = new Deal_HitchRecord(this, this.hitchDatagrid);
            mDeal_HitchRecord.prepareData();
            mSlide = new Slide(this.util_slide_grid, this.util_calc_panel, this.Dispatcher);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            this.mDeal_HitchRecord.addData();
        }

        private void hitchDatagrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            DataGrid _this = sender as DataGrid;
            CheckBox _hitchLock = _this.Columns[0].GetCellContent(e.Row).FindName("hitchLock") as CheckBox;
            int _index = e.Row.GetIndex();

        }

        private void hitch_SaveSelfbtn_Click(object sender, RoutedEventArgs e)
        {
            Button _this = (Button)sender;

            this.mDeal_HitchRecord.saveData(_this.DataContext);
            
        }

        private void hitch_SaveAllBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Button _this = (Button)sender;
            TextBox _screen = this.calc_screen;
            String _val = (String)_this.Content;

            if ("Res".Equals(_val))
            {
                _screen.Text = "";
            }
            else if ("=".Equals(_val))
            {
                String _expr = _screen.Text;

                String _result = Util_Calc.Calc(_expr);

                _screen.Text = _result;

            }
            else

                _screen.Text += _val;
        }

        private void util_calc_Click_1(object sender, RoutedEventArgs e)
        {
            mSlide.runSelf();
        }

        //private void oTimerCallback(object o)
        //{
        //    this.Dispatcher.BeginInvoke(
        //      delegate()
        //      {
        //          double _start = (double)o;
        //          show_calc(_start);
        //      });
        //}

        //private int fade_state = 0;
        //private void show_calc(double aStartWidth)
        //{
        //    if (aStartWidth < 40)
        //    {
        //        if (util_slide_grid.ColumnDefinitions[0].Width.Value >= 73d)
        //        {
        //            util_calc_panel.Visibility = Visibility.Visible;
        //            util_calc_panel.Opacity = 1.0d;
        //            util_slide_grid.ColumnDefinitions[0].Width = new GridLength(73, GridUnitType.Star);
        //            this.mTimer.Dispose();
        //        }
        //        else
        //        {
        //            util_calc_panel.Visibility = Visibility.Visible;
        //            util_calc_panel.Opacity += 0.05d;
        //            double _temp = util_slide_grid.ColumnDefinitions[0].Width.Value;
        //            util_slide_grid.ColumnDefinitions[0].Width = new GridLength(_temp + 3, GridUnitType.Star);
        //        }
        //    }
        //    else
        //    {
        //        if (util_slide_grid.ColumnDefinitions[0].Width.Value <= 13d)
        //        {
        //            util_calc_panel.Visibility = Visibility.Collapsed;
        //            util_calc_panel.Opacity = 0.0d;
        //            util_slide_grid.ColumnDefinitions[0].Width = new GridLength(13, GridUnitType.Star);
        //            this.mTimer.Dispose();
        //        }
        //        else
        //        {
        //            util_calc_panel.Opacity -= 0.05d;
        //            double _temp = util_slide_grid.ColumnDefinitions[0].Width.Value;
        //            util_slide_grid.ColumnDefinitions[0].Width = new GridLength(_temp - 3, GridUnitType.Star);
        //        }
        //    }
        //}
    }
}
